package com.jjwxc.jwjskandriod.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.jjwxc.jwjskandriod.fragment.AllSuggestFragment
import com.jjwxc.jwjskandriod.fragment.DerivativeFragment
import com.jjwxc.jwjskandriod.fragment.WebFragment
import com.jjwxc.jwjskandriod.model.LoginResponse

class MainSuggestAdapter(fm: FragmentManager?) :
    FragmentPagerAdapter(fm!!) {
    private var list: ArrayList<LoginResponse.DataBean.BookCenterTabBean> = ArrayList()

    // 菜单标题
    private val TAB_TITLES = arrayOf("推荐", "言情", "纯爱", "衍生")

    override fun getItem(i: Int): Fragment {
        //        list.forEach {
        var fragment: Fragment? = if (list[i].tabType.equals("NATIVE")) {
                    when (list[i].name) {
                        TAB_TITLES[0] -> AllSuggestFragment()
                        TAB_TITLES[1] -> DerivativeFragment("1", "1")
                        TAB_TITLES[2] -> DerivativeFragment("2", "2")
                        TAB_TITLES[3] -> DerivativeFragment("3", "3")
                        else -> WebFragment().newInstance(list[i].url)
                    }
            } else {
                WebFragment().newInstance(list[i].url)
            }
//        }

        return fragment!!
    }

    override fun getCount(): Int = list.size

    fun setList(list: ArrayList<LoginResponse.DataBean.BookCenterTabBean>) {
        this.list = list
    }
}